package com.myzl.coal.client.config;

import com.myzl.coal.client.parse.CommonParseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.AnnotationUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author sl
 */
@Slf4j
@Configuration
public class LocalCommunicationBean {

    @Bean(name= "parseServiceMap")
    public Map<Integer, CommonParseService> setOrderHandleMap(List<CommonParseService> services) {

        Map<Integer, CommonParseService> result=new HashMap<>(16);
        services.stream().forEach(e->{
            int deviceType = AnnotationUtils.findAnnotation(e.getClass(), LocalCommunicationParse.class).deviceType();
            result.put(deviceType,e);
        });

        return result;
    }
}
